import tensorflow as tf

from tensorflow.examples.tutorials.mnist import input_data


mnist = input_data.read_data_sets('D:/box/mnist',one_hot=True)

x = tf.placeholder(dtype=tf.float32,shape=[None,784])
y = tf.placeholder(dtype=tf.float32,shape=[None,10])

w1 = tf.Variable(tf.zeros([784,10]))
b1 = tf.Variable(tf.zeros([1,10]))
actv = tf.nn.softmax(tf.matmul(x,w1)+b1)
loss = -tf.reduce_sum(y*tf.log(actv))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
init = tf.global_variables_initializer()
with tf.Session() as sess:
    sess.run(init)

    for i in range(100):
        bx,by = mnist.train.next_batch(50)
        sess.run(train_step,feed_dict={x:bx,y:by})

        bvx,bvy = mnist.validation.next_batch(50)
        predication = tf.equal(tf.argmax(actv,1),tf.argmax(y,1))
        mean = tf.reduce_mean(tf.cast(predication,dtype=tf.float32))
        print(sess.run(mean,feed_dict={x:bvx,y:bvy}))



